package com.example.flowable.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.annotations.Autowired;
import com.example.annotations.Service;
import com.example.db.SqlBuilder;
import com.example.db.TableService;
import com.example.db.model.IPage;
import com.example.flowable.model.FlowableModel;
import com.example.flowable.service.FlowableModelService;
import org.flowable.engine.TaskService;

import java.util.List;

/**
 * @Classname FlowableModelServiceImpl
 * @Description TODO
 * @Date 2022/8/15 12:38
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@Service
public class FlowableModelServiceImpl implements FlowableModelService {

    @Autowired
    TableService tableService;

    @Override
    public FlowableModel save(FlowableModel flowableModel) {
        tableService.save(flowableModel,FlowableModel.class);
        return flowableModel;
    }

    @Override
    public FlowableModel getById(Object id) {
        FlowableModel flowableModel=tableService.getOneById(id,FlowableModel.class);
        return flowableModel;
    }

    @Override
    public FlowableModel updateById(FlowableModel flowableModel) {
        tableService.updateById(flowableModel,FlowableModel.class);
        return flowableModel;
    }

    @Override
    public IPage<FlowableModel> page(Integer pageNum, Integer pageSize, JSONObject obj) {
        SqlBuilder sqlBuilder=tableService.getSqlBuilder(FlowableModel.class);
        if(obj != null){

        }
        sqlBuilder.orderByDesc("createdate");
        sqlBuilder.page(pageNum,pageSize);
        return tableService.getPage(sqlBuilder,FlowableModel.class);
    }

    @Override
    public List<FlowableModel> getFlowableModelList() {
        SqlBuilder sqlBuilder=tableService.getSqlBuilder(FlowableModel.class);
        sqlBuilder.and("status").eq(1);
        List<FlowableModel> flowableModels=tableService.selectList(sqlBuilder,FlowableModel.class);
        return flowableModels;
    }
}
